package com.xltq.service.impl;

import com.xltq.dao.IUserDao;
import com.xltq.entity.User;
import com.xltq.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

@Service("userService")
public class IUserServiceImpl implements IUserService {
    @Autowired
    private IUserDao iUserDao;
    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public boolean aBoolean(String username, String password) {
        User user = iUserDao.loginUser(username);
        if (ObjectUtils.isEmpty(user)) {
            return false;
        }
        String userName = user.getUsername();
        String passWord = user.getPassword();
        if (userName.equals(username) && passWord.equals(password)) {
            return true;
        }
        return false;
    }
    @Transactional(rollbackFor=Exception.class)
    @Override
    public int insertUser(User user) {
        if (ObjectUtils.isEmpty(user)) {
            return 0;
        }
        int i = iUserDao.insertUser(user);

        return i;
    }
}
